package com.ufida.ids.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hereway.core.dao.IBaseDAO;
import com.hereway.core.exception.ServiceException;
import com.hereway.core.service.BaseServiceImpl;
import com.ufida.ids.dao.IUserMappingDAO;
import com.ufida.ids.model.AppModel;
import com.ufida.ids.model.StaffModel;
import com.ufida.ids.model.UserMappingModel;
import com.ufida.ids.service.IAppService;
import com.ufida.ids.service.IStaffService;
import com.ufida.ids.service.IUserMappingService;

@Service("userMappingService")
public class UserMappingServiceImpl extends BaseServiceImpl<UserMappingModel, Long> implements IUserMappingService {

	@Autowired
	IUserMappingDAO userMappingDAO;
	
	@Autowired
	IAppService appService;
	
	@Autowired
	IStaffService staffService;
	
	@Override
	protected IBaseDAO<UserMappingModel, Long> getDAO() {
		return userMappingDAO;
	}

	@Override
	public UserMappingModel findByUserApp(String staffCode, String appCode) throws ServiceException {
		StaffModel staff = staffService.getByCode(staffCode);
		AppModel app = appService.getByCode(appCode);
		
		if(staff != null && app != null){
			return userMappingDAO.findByUserApp(staff.getStaffId(), app.getAppId());
		}
		return null;
	}
	
	public UserMappingModel findByUserApp(Long staffId, Long appId) throws ServiceException {
		return userMappingDAO.findByUserApp(staffId, appId);
	}
	
	
}
